<?php
/**
 * Created by Adon.
 * User: Adon
 * Date: 2017/12/28
 * Time: 15:53
 */
$this->title = '门店提现管理';
$url_manager = Yii::$app->urlManager;
?>

<div class="panel mb-3">
    <div class="panel-header">
        <span><?= $this->title ?></span>



        <div class="mb-3 clearfix">
            <div class="p-4 bg-shaixuan">
                <form method="get">

                    <?php $_s = ['keyword', 'keyword_1', 'date_start', 'date_end', 'page', 'per-page'] ?>
                    <?php foreach ($_GET as $_gi => $_gv) :
                        if (in_array($_gi, $_s)) {
                            continue;
                        } ?>
                        <input type="hidden" name="<?= $_gi ?>" value="<?= $_gv ?>">
                    <?php endforeach; ?>
                    <div flex="dir:left">
                        <div>
                            <div class="input-group">
                                <input class="form-control"
                                       placeholder="门店名称"
                                       name="keyword"
                                       autocomplete="off"
                                       value="<?= isset($_GET['keyword']) ? trim($_GET['keyword']) : null ?>"><span
                                        class="input-group-btn"><button class="btn btn-primary">搜索</button></span>

                                &nbsp;  &nbsp;  &nbsp;
                                <div>
                                    <label>申请时间：</label>
                                </div>
                                <div>
                                    <div class="input-group">
                                        <input class="form-control" id="date_start" name="date_start"
                                               autocomplete="off"
                                               value="<?= isset($_GET['date_start']) ? trim($_GET['date_start']) : '' ?>">
                                        <span class="input-group-btn">
                                            <a class="btn btn-secondary" id="show_date_start" href="javascript:">
                                                <span class="iconfont icon-daterange"></span>
                                            </a>
                                        </span>
                                        <span class="middle-center" style="padding:0 4px">至</span>
                                        <input class="form-control" id="date_end" name="date_end"
                                               autocomplete="off"
                                               value="<?= isset($_GET['date_end']) ? trim($_GET['date_end']) : '' ?>">
                                        <span class="input-group-btn">
                                            <a class="btn btn-secondary" id="show_date_end" href="javascript:">
                                                <span class="iconfont icon-daterange"></span>
                                            </a>
                                        </span>
                                    </div>
                                </div>
                                <div class="middle-center">
                                    <a href="javascript:" class="new-day" data-index="7">近7天</a>
                                    <a href="javascript:" class="new-day" data-index="30">近30天</a>
                                </div>
                            </div>
                            <div flex="dir:left">
                                <div style="margin-top: 15px;" class="mr-4">
                                    <div class="form-group">
                                        <button class="btn btn-primary mr-4">筛选</button>
                                        <a class="btn btn-secondary export-btn"
                                           href="javascript:" hidden>批量导出</a>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
            </div>

        </div>



        <ul class="nav nav-right" hidden>
            <li class="nav-item">
                <a class="nav-link <?= !isset($get['status']) || $get['status'] == -1 ? 'active' : null ?>"
                   href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => -1]) ?>">全部</a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?= !isset($get['status']) || $get['status'] == 0 ? 'active' : null ?>"
                   href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => 0]) ?>">待审核</a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?= isset($get['review_status']) && $get['status'] == 1 ? 'active' : null ?>"
                   href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => 1]) ?>">已通过</a>
            </li>
            <li class="nav-item">
                <a class="nav-link <?= isset($get['review_status']) && $get['status'] == 2 ? 'active' : null ?>"
                   href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => 2]) ?>">未通过</a>
            </li>
        </ul>

    </div>
    <div class="panel-body">


        <div class="mb-4">
            <ul class="nav nav-tabs status">
                <li class="nav-item">
                    <a class="status-item nav-link <?= !isset($get['status']) || $get['status'] == -1 ? 'active' : null ?>"
                       href="<?= $url_manager->createUrl(['mch/mch/index/cash']) ?>">全部</a>
                </li>
                <li class="nav-item">
                    <a class="status-item nav-link  <?= !isset($get['status']) || $get['status'] == 0 ? 'active' : null ?>"
                       href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => 0]) ?>">未审核<?= $count['count_1'] ? "(" . $count['count_1'] . ")" : null ?></a>
                </li>
                <li class="nav-item">
                    <a class="status-item nav-link <?= isset($get['review_status']) && $get['status'] == 1 ? 'active' : null ?>"
                       href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => 1]) ?>">已打款<?= $count['count_2'] ? "(" . $count['count_2'] . ")" : null ?></a>
                </li>
                <li class="nav-item">
                    <a class="status-item nav-link  <?= isset($get['review_status']) && $get['status'] == 2 ? 'active' : null ?>"
                       href="<?= $url_manager->createUrl(['mch/mch/index/cash', 'status' => 2]) ?>">无效<?= $count['count_3'] ? "(" . $count['count_3'] . ")" : null ?></a>
                </li>
            </ul>
        </div>


        <?php if (!$list || count($list) == 0) : ?>
            <div class="p-5 text-center text-muted">暂无提现记录</div>
        <?php else : ?>
            <table class="table table-bordered">
                <thead>
                <tr>
                    <th>ID</th>
                    <th>门店</th>
                    <th hidden>用户</th>
                    <th>账户信息</th>
                    <th>提现金额</th>
                    <th>时间</th>
                    <th>操作</th>
                </tr>
                </thead>
                <?php foreach ($list as $item) : ?>
                    <tr>
                        <td><?= $item['id'] ?></td>
                        <td><?= $item['name'] ?></td>
                        <td hidden><?= $item['nickname'] ?></td>
                        <td><?=$item['account_content']?></td>
                        <td><?= $item['money'] ?></td>
                        <td><?= $item['addtime'] ?></td>
                        <td>
                            <?php if ($item['status'] == 0) : ?>
                                <a class="transfer-confirm" data-warning="确认通过？资金将转入门店银行卡。"
                                   data-toggle="tooltip" data-placement="bottom"
                                   title="转账--用于微信自动打款（需要开通企业付款到银行卡）"
                                   href="<?= $url_manager->createUrl(['mch/mch/index/cash-submit', 'status' => 1, 'id' => $item['id'],]) ?>">转账</a>
                                <span>|</span>
                                <a class="transfer-confirm" data-warning="确认通过？提现记录将被标记为已打款。"
                                   data-toggle="tooltip" data-placement="bottom"
                                   title="确认打款--用于线下打款，后台标记提现记录为已打款"
                                   href="<?= $url_manager->createUrl(['mch/mch/index/cash-submit', 'status' => 3, 'id' => $item['id'],]) ?>">确认打款</a>
                                <span>|</span>
                                <a class="transfer-confirm" data-warning="确认拒绝？资金将反之商户账户余额。"
                                   data-toggle="tooltip" data-placement="bottom"
                                   title="拒绝--用于拒绝商户该次提现"
                                   href="<?= $url_manager->createUrl(['mch/mch/index/cash-submit', 'status' => 2, 'id' => $item['id'],]) ?>">拒绝</a>
                            <?php else : ?>
                                <?php if ($item['status'] == 1) : ?>
                                    <span class="text-success">已转账</span>
                                <?php else : ?>
                                    <span class="text-danger">已拒绝</span>
                                <?php endif; ?>
                            <?php endif; ?>
                        </td>
                    </tr>
                <?php endforeach; ?>
            </table>
            <?= \yii\widgets\LinkPager::widget(['pagination' => $pagination]) ?>
        <?php endif; ?>
    </div>
</div>
<?= $this->render('/layouts/ss', [
    'exportList' => $exportList
]) ?>
<script>
    $(document).on('click', '.transfer-confirm', function () {
        var btn = $(this);
        $.confirm({
            content: btn.attr('data-warning'),
            confirm: function () {
                $.loading();
                $.ajax({
                    url: btn.attr('href'),
                    dataType: 'json',
                    success: function (res) {
                        $.alert({
                            content: res.msg,
                            confirm: function () {
                                location.reload();
                            }
                        });
                    }
                });
            },
        });
        return false;
    });
</script>
